/*
 * @Description:
 * @Author: maxyang
 * @Date: 2022-05-17 21:41:43
 * @LastEditTime: 2022-07-06 20:59:06
 * @LastEditors: liutq
 * @Reference:
 */
package sms

import (
	"time"

	"github.com/maxyang107/jinglan/model"
)

type VerificationCode struct {
	ID         uint       `gorm:"column:id; parimary_key" json:"id"`
	Phone      int64      `gorm:"column:phone" json:"phone"`
	SmsCode    string     `gorm:"column:sms_code" json:"sms_code"`
	Scene      uint8      `gorm:"column:scene" json:"scene"`
	Status     uint8      `gorm:"column:status" json:"status"`
	Expiretime *time.Time `gorm:"column:expiretime" json:"expiretime"`
}

func Save(sms_ VerificationCode) {
	model.Db.Create(&sms_)
}

func FindSmsCodeByPhoneAndSeace(phone int64, scene uint8) *VerificationCode {
	sms := &VerificationCode{}
	model.Db.Where(&VerificationCode{Phone: phone, Scene: scene, Status: 0}).Order("id desc").First(sms)
	return sms
}

func Update(sms_ *VerificationCode) {
	sms_.Status = 1
	model.Db.Model(&VerificationCode{}).Where(&VerificationCode{ID: sms_.ID}).Update(&sms_)
}
